package com.sh.限流算法.滑动时间窗口算法;

public class SlidingWindowRateLimiterManualTest {
    public static void main(String[] args) throws InterruptedException {
        SlidingWindowRateLimiter rateLimiter = new SlidingWindowRateLimiter();

        System.out.println("Testing sliding window rate limiter:");
        // 前 100 个请求应该不限流
        for (int i = 0; i < 1000; i++) {
            Thread.sleep(5);
            boolean allowed = rateLimiter.limit();
//            System.out.println("请求 " + (i + 1) + " 通过？ " + allowed);
        }



        try {
            // 等待一段时间，让窗口滑动
            Thread.sleep(200);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }

        // 新窗口下第一个请求应该不限流
        boolean newRequestAllowed = rateLimiter.limit();
        System.out.println("New request after sliding allowed: " + newRequestAllowed);
    }
}